package org.example.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author xuan
 * @create 2023/9/12
 */
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        //向管道加入处理器

        //得到管道
        ChannelPipeline pipeline = channel.pipeline();

        //加入一个netty提供的HttpServerCodec  其中codec是coder编码和decoder解码的缩写
        //HttpServerCodec说明：它是netty提供的处理http的编码解码器
        pipeline.addLast("MyHttpServerCodec", new HttpServerCodec());

        //增加一个自定义的handler
        pipeline.addLast("MyTestHttpServerHandler", new TestHttpServerHandler());

        System.out.println("ok~~~~~~");
    }
}
